<template>
    <div class="greybg">
      <span @click="modal = true">
        <img src="http://www.keruyun.com/sem/brand/images/efficient_02.jpg" alt="" width="100%" style="cursor :pointer">
      </span>
      <Modal
        width="700"
        v-model="modal"
        @on-cancel="cancel">
        <video-player  class="video-player vjs-custom-skin"
           ref="videoPlayer"
           :playsinline="true"
           :options="playerOptions">
        </video-player>
        <div slot="footer">
        </div>
      </Modal>
    </div>
</template>

<script>
import { videoPlayer } from 'vue-video-player'
export default {
  name: 'VideoPlayer',
  data () {
    return {
      modal: false,
      playerOptions: {
        playbackRates: [0.7, 1.0, 1.5, 2.0],
        autoplay: false, // 如果true,浏览器准备好时开始回放。
        muted: false, // 默认情况下将会消除任何音频。
        loop: false, // 导致视频一结束就重新开始。
        preload: 'auto', // 建议浏览器在<video>加载元素后是否应该开始下载视频数据。auto浏览器选择最佳行为,立即开始加载视频（如果浏览器支持）
        language: 'zh-CN',
        aspectRatio: '16:9',
        fluid: true,
        sources: [{
          type: '',
          src: 'http://imgw.keruyun.net/uploads/e9f354391d133a9111c6546f8915ff7d.mp4'
        }],
        poster: '../../static/images/test.jpg',
        // width: document.documentElement.clientWidth,
        notSupportedMessage: '此视频暂无法播放，请稍后再试',
        controlBar: {
          timeDivider: true,
          durationDisplay: true,
          remainingTimeDisplay: false,
          fullscreenToggle: true
        }
      }
    }
  },
  methods: {
    cancel () {
      this.$refs.videoPlayer.player.pause()
    }
  },
  components: {
    videoPlayer
  },
  computed: {
    player () {
      return this.$refs.videoPlayer.player
    }
  }
}
</script>

<style lang="stylus" scoped>
  .ivu-modal-footer {
    display: none
  }
  .greybg {
    background: #e2e2e2;
    padding-top: 1rem;
    margin-top: -1rem;
    overflow: hidden;
  }
</style>
